package sdk.webview.fmc.com.fmcsdk.imagepicker.task;

import android.content.Context;
import android.provider.MediaStore;
import android.util.Log;

import com.google.gson.Gson;

import sdk.webview.fmc.com.fmcsdk.imagepicker.bean.MediaFile;
import sdk.webview.fmc.com.fmcsdk.imagepicker.loader.ImageScanner;
import sdk.webview.fmc.com.fmcsdk.imagepicker.loader.MediaHandler;
import sdk.webview.fmc.com.fmcsdk.imagepicker.loader.MediaLoadCallback;

import java.util.ArrayList;

/**
 * 媒体库扫描任务（图片）
 */
public class ImageLoadTask implements Runnable {

    private Context mContext;
    private ImageScanner mImageScanner;
    private MediaLoadCallback mMediaLoadCallback;

    public ImageLoadTask(Context context, MediaLoadCallback mediaLoadCallback) {
        this.mContext = context;
        this.mMediaLoadCallback = mediaLoadCallback;
        mImageScanner = new ImageScanner(context);
    }

    @Override
    public void run() {
        //存放所有照片
        ArrayList<MediaFile> imageFileList = new ArrayList<>();
        if (mImageScanner != null) {
            imageFileList = mImageScanner.queryMedia(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            Log.e("shuchang", "imageFileList--->" + new Gson().toJson(imageFileList));
        }
        if (mMediaLoadCallback != null) {
            mMediaLoadCallback.loadMediaSuccess(imageFileList, null, MediaHandler.getImageFolder(mContext, imageFileList));
        }

    }

}
